package com.hrma.controller;

import com.github.pagehelper.Page;
import com.hrma.entity.*;
import com.hrma.services.OvertimeRecordService;
import com.hrma.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/overtimeRecord")
@Slf4j
public class OvertimeRecordController {
    @Autowired
    private final OvertimeRecordService overtimeRecordService;

    public OvertimeRecordController(OvertimeRecordService overtimeRecordService) {
        this.overtimeRecordService = overtimeRecordService;
    }

    @PostMapping("/add")
    public Result<OvertimeRecordVO> add(@RequestBody OvertimeRecordVO data){
        log.debug("收到add请求，请求参数：{}", data);
        return Result.ok(overtimeRecordService.add(data));
    }

    @GetMapping("/select")
    public Result<List<SelectResult>> select() {
        log.debug("收到select请求！");
        return Result.ok(overtimeRecordService.select());
    }

    @PostMapping("/list")
    public Result<ListWithCount<OvertimeRecordVO>> getList(@RequestBody OvertimeRecordDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<OvertimeRecordVO> res = overtimeRecordService.getList(data);
        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }

    @PostMapping("/personalList")
    public Result<ListWithCount<OvertimeRecordVO>> getPersonalList(@RequestBody OvertimeRecordDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<OvertimeRecordVO> res = overtimeRecordService.getPersonalList(data);
        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }
}
